﻿@model OT.Models.Users
@{
     
    ViewBag.Title = "RecoverPassWord";
}

<h2>RecoverPassWord</h2>
<table>
    <tr>
        <td>
  @using (Html.BeginForm())
                {
                    @Html.AntiForgeryToken()
                    @Html.ValidationSummary(true)

                    <div id="alert_modal">
                        @Html.ValidationSummary()
                    </div>
                 <div id="activationcode"></div>
                    <div class="editor-label">
                        @Html.LabelFor(model => model.Password)
                    </div>
                    <div class="editor-field">
                        @Html.PasswordFor(model => model.Password, new { @maxlength = "20" })
                        <span id="pass" style="color: red"></span>
                        @Html.ValidationMessageFor(model => model.Password)
                    </div>

                    <div class="editor-label">
                        @Html.LabelFor(model => model.ConfirmPassword)
                    </div>
                    <div class="editor-field">
                        @Html.PasswordFor(model => model.ConfirmPassword, new { @maxlength = "20" })
                        <span id="cpass" style="color: red"></span>
                        @Html.ValidationMessageFor(model => model.ConfirmPassword)
                    </div>

                  
                }

                <div>
                    <button class="btn btn-primary" type="submit" id="btnCreate1"><i class="icon-cog"></i>Save</button>
                    <button class="btn btn-primary" id="btncancel"><i class="icon-off"></i>Cancel</button>
                </div>
            </td>
        </tr>
    <tr>

        <td>
            <br />
             <div id="msg" style="color:red;font-size:18px"></div>
                <div id="msg1" style="color:gray;font-size:10px"></div>
        </td>
    </tr>
       
    </table>
<script>
    $(document).on("click", "#btncancel", null, function (e) {
        window.location.href = '@Url.Content("~/Home")';
    })
 $(document).on("click", "#btnCreate1", null, function (e) {

     
        var Password = btoa($("#Password").val());
        var confirmpassword = $("#ConfirmPassword").val();
       
        e.preventDefault();
        $(".error").hide();

        if (Password == '') {
            $('#alert_danger2').children('.alert:first-child').remove()
            $("#Password").after(' <span id="alert_danger2"></span>');
            bootstrap_alert.danger2('Please enter Password..');
            $("#Password").focus()
        }
        else if (Password.length < 6) {
            $('#alert_danger2').children('.alert:first-child').remove()
            $('#alert_info').children('.alert:first-child').remove()
            $("#Password").after(' <span id="alert_danger2"></span>');
            bootstrap_alert.danger2('PassWord Must be 6 character long.');
        }
        
        else if (!Password.match(/([a-z].*[A-Z])|([A-Z].*[a-z])/)) {
            $('#alert_danger2').children('.alert:first-child').remove()
            $('#alert_info').children('.alert:first-child').remove()
            $("#Password").after(' <span id="alert_info"></span>');
            bootstrap_alert.info('Password should be contain Character in Upper & Lower Case.');
        }
        else if (confirmpassword == '') {
            $('#alert_danger3').children('.alert:first-child').remove()
            $("#ConfirmPassword").after(' <span id="alert_danger3"></span>');
            bootstrap_alert.danger3('Please enter Confirm Password.');
            $("#ConfirmPassword").focus()
        }

        else {
            var activationcode = '@Request.QueryString["ActivationCode"]';
            var rl = "/Home/RecoverPassWord?Password=" + Password + "&guid=" + activationcode
            $.ajax({
                url: rl,
                type: "POST",
                success: function (result) {
                    if (result != "Notvalid") {
                        $("#msg").after(' <span id="alert_success"></span>');
                        bootstrap_alert.success('PassWord Successfully Changed.');
                        setTimeout(function () { window.location.href = '@Url.Content("~/Home")'; }, 3000);
                    }
                    else {
                        $('#alert_danger3').children('.alert:first-child').remove()
                        $('#alert_danger2').children('.alert:first-child').remove()
                        $('#alert_success').children('.alert:first-child').remove()
                        $("#msg").after(' <span id="alert_danger"></span>');
                        bootstrap_alert.danger('PassWord Not Changed !!.');
                    }
                },
                error: function (data) {
                }
            });
        }
        return false;
 });
    function alertTimeout(wait) {
        setTimeout(function () {
            $('#alert_placeholder').children('.alert:first-child').remove()
        }, wait);
    }

    bootstrap_alert = function () { }
    bootstrap_alert.danger = function (message) {
        $('#alert_danger').html('<span class="alert alert-danger"><strong>' + "Message! " + '</strong><span>' + message + '</span></span>')

    }
    bootstrap_alert.danger2 = function (message) {
        $('#alert_danger2').html('<span class="alert alert-danger"><strong>' + "Message! " + '</strong><span>' + message + '</span></span>')

    }
    bootstrap_alert.danger3 = function (message) {
        $('#alert_danger3').html('<span class="alert alert-danger"><strong>' + "Message! " + '</strong><span>' + message + '</span></span>')
    }
  
    bootstrap_alert.success = function (message) {
        $('#alert_success').html('<span class="alert alert-success"><strong>' + "Message! " + '</strong><span>' + message + '</span></span>')
    }
    bootstrap_alert.info = function (message) {
        $('#alert_info').html('<span class="alert alert-info"><strong>' + "Message! " + '</strong><span>' + message + '</span></span>')
    }
    $('#Password').focusout(function () {
        $(".error2").hide();
        var fname = $("#Password").val();
        if (fname == " ") {
            $('#alert_danger2').children('.alert:first-child').remove()
            $('#alert_info').children('.alert:first-child').remove()
            $("#Password").after(' <span id="alert_danger2"></span>');
            bootstrap_alert.danger2('Please enter Password..');
        } else if (fname.length < 6) {
            $('#alert_danger2').children('.alert:first-child').remove()
            $('#alert_info').children('.alert:first-child').remove()
            $("#Password").after(' <span id="alert_danger2"></span>');
            bootstrap_alert.danger2('PassWord Must be 6 character long.');
        }
        else if (!fname.match(/([!,%,&,#,$,^,*,?,_,~,@@])/)) {
            $('#alert_danger2').children('.alert:first-child').remove()
            $('#alert_info').children('.alert:first-child').remove()
            $("#Password").after(' <span id="alert_danger2"></span>');
            bootstrap_alert.danger2('Password should be contain Special Character..');

        }
        else if (!fname.match(/([a-z].*[A-Z])|([A-Z].*[a-z])/)) {
            $('#alert_danger2').children('.alert:first-child').remove()
            $('#alert_info').children('.alert:first-child').remove()
            $("#Password").after(' <span id="alert_info"></span>');
            bootstrap_alert.info('Password should be contain Character in Upper & Lower Case.');
        }
        else {
            $('#alert_danger2').children('.alert:first-child').remove()
            $('#alert_info').children('.alert:first-child').remove()
            return false;
        }
    });

    $('#ConfirmPassword').focusout(function () {
        $(".error13").hide();
        var pass = $("#Password").val();
        var cpass = $('#ConfirmPassword').val();
        if (pass == "") {
            $('#alert_danger3').children('.alert:first-child').remove()
            $("#ConfirmPassword").after(' <span id="alert_danger3"></span>');
            bootstrap_alert.danger3('Please enter Confirm Password.');
        } else if (cpass != pass) {
            $('#alert_danger3').children('.alert:first-child').remove()
            $("#ConfirmPassword").after(' <span id="alert_danger3"></span>');
            bootstrap_alert.danger3('PassWord Not Matched.');

        }
        else {
            $('#alert_danger3').children('.alert:first-child').remove();
            $(".error13").hide();
            return false;
        }
    });

</script>